package com.example.apigateway.utils;

import com.google.common.io.Files;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

import java.time.Instant;

/**
 * @author ：Anitaxiaofeng
 * @description：
 * @create 2018-06-27
 **/
public class FileUtil {


    public static File saveToLocal(MultipartFile file, String filePath) throws IOException {
        File newFile = new File(filePath+"/" + Instant.now().getEpochSecond()+"/"+file.getOriginalFilename());
        if(!newFile.exists()) {
            newFile.getParentFile().mkdirs();
            newFile.createNewFile();
        }
        Files.write(file.getBytes(),newFile);
        return newFile;
    }
}


